package com.wms.ymcc.es;

import com.wms.ymcc.SearchApp;
import com.wms.ymcc.doc.CourseDoc;
import com.wms.ymcc.repository.EsCrudRepository;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import org.junit.Test;
import java.util.ArrayList;

/**
 * @author : 阿盛哟
 * @description :
 * @createDate : 2025/6/18 17:39
 */

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SearchApp.class)
public class ESTest {

    @Autowired
    private ElasticsearchRestTemplate template;

    @Autowired
    private EsCrudRepository repository;

    @Test
    public void test3(){
        //删除
        repository.deleteById(100l);
    }

    @Test

    public void test4(){
        //查询
//        repository.search("springCloudAlibaba");
    }


    @Test
    public void test2(){
        //批量保存
        ArrayList<CourseDoc> courseDocs = new ArrayList<>();

        for (long i = 1; i < 101; i++) {
            CourseDoc courseDoc = new CourseDoc();
            courseDoc.setId(i);
            courseDoc.setName("springCloudAlibaba大神");
            courseDoc.setCourseTypeId(i);
            courseDocs.add(courseDoc);
        }
        repository.saveAll(courseDocs);
    }

    @Test
    public void test1(){
        // 创建索引
        template.createIndex(CourseDoc.class);

        // 创建映射
        template.putMapping(CourseDoc.class);

    }

}